﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using BookiFramework.Files.Compression;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BookiFramework.net45.Test.FilesTest
{    
    [TestClass]
    public class ZipTest
    {
        public const string demoZipFile = "Demo.zip";
        public const string demoFile = "Demo.txt";
        public const string demoWriteFile = "DemoWrite.txt";
        public const string demozippedFile = "DemoZipped.zip";
        
        [TestMethod]
        public void Test_zip_files_success()
        {
            //Arrange

            var zipper = new Zipper();

            //Act
             var result =zipper.Zip(fileTarget: demoZipFile,files:demoFile);

            //Assert
            Assert.IsTrue(result.IsCorrect);
            Assert.IsTrue(File.Exists(demoZipFile));
        }

        [TestMethod]
        public void Test_zip_files_fail_file_not_exist()
        {
            //Arrange

            var zipper = new Zipper();

            //Act
            var result = zipper.Zip(fileTarget: demoZipFile, files: "no existo.txt");

            //Assert
            Assert.IsFalse(result.IsCorrect);            
        }

        [TestMethod]
        public void Test_unzip_files_success()
        {
            //Arrange
            var zipper = new Zipper();
            const string directory = "Files";
 
            //Act
            var result = zipper.UnZipToDirectory(zipFile:demozippedFile,directoryToExtract:directory);
            var fileInfo = Directory.GetFiles(directory);
            
            //Assert
            Assert.IsTrue(result.IsCorrect);
            Assert.AreEqual(fileInfo.Count(),4);
        }

        [TestMethod]
        public void Test_zip_files_success_with_memory_stream()
        {
            //Arrange

            var zipper = new Zipper();            
            //Act
            var memory = zipper.Zip(files:demoFile);

            //Assert
            Assert.IsNotNull(memory);            
            Assert.IsTrue(memory.Length > 0);            
        }
    }
}